package JavaEE初阶;

public class Demo03 {
    //notify方法的使用要搭配wait
    public static void main(String[] args) {
        Object object = new Object();
        //让t1线程调用wait方法进入阻塞等待
        Thread t1 = new Thread(() ->{
            synchronized (object){
                System.out.println("t1线程调用wait方法之前");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1线程调用wait方法之后");
            }
        });
        //让t2线程调用notify方法进行唤醒
        Thread t2 = new Thread(() ->{
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            synchronized (object){
                System.out.println("t2线程调用notify对t1线程进行唤醒");
                object.notify();
            }
        });
        t1.start();
        t2.start();
    }
}
